package com.example.guiguihomemedical.service.impl;

import com.example.guiguihomemedical.entity.dto.CountTotal;
import com.example.guiguihomemedical.entity.dto.RecordList;
import com.example.guiguihomemedical.mapper.CountTotalMapper;
import com.example.guiguihomemedical.service.CountTotalService;
import com.example.guiguihomemedical.service.RecordListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CountTotalServiceImpl implements CountTotalService {
    @Autowired
    private CountTotalMapper countTotalMapper;
    @Autowired
    private RecordListService recordListService;
    @Override
    public CountTotal getCountTotal() {
        CountTotal countTotal=new CountTotal();
        Integer recordTotal=countTotalMapper.getRecordTotal();
        Integer followUpTotal=countTotalMapper.getFollowUpTotal();
        Integer toBeSigning=0;
        Integer signed=0;
        Integer signingExpiration=0;
        List<RecordList> recordLists= recordListService.getRecordList();
        for(RecordList recordList:recordLists){
            if(recordList.getStatus()==0){
                toBeSigning=toBeSigning+1;
            }
            if(recordList.getStatus()==1){
                signed=signed+1;
            }
            if(recordList.getStatus()==2){
                signingExpiration=signingExpiration+1;
            }
        }
        countTotal.setRecordTotal(recordTotal);
        countTotal.setFollowUpTotal(followUpTotal);
        countTotal.setToBeSigned(toBeSigning);
        countTotal.setSigned(signed);
        countTotal.setSigningExpiration(signingExpiration);
        return countTotal;
    }
}
